package com.zhou;

import java.util.Scanner;

/**
 * T23
 *
 * @author zhouxianfeng
 * @date 2021-9-9
 */
public class T23 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();
        int gap = sc.nextInt();
        int[] buildings = new int[num];
        for (int i = 0; i < num; i++) {
            buildings[i] = sc.nextInt();
        }
        resolve1(buildings, gap);
    }

    //暴力解法
    public static void resolve(int[] buildings, int gap) {
        int length = buildings.length;
        int start, middle, end;
        int total = 0;

        for (int i = 0; i < length - 2; i++) {
            start = buildings[i];
            for (int j = length - 1; j > i + 1; j--) {
                end = buildings[j];
                if (end - start <= gap) {
                    total += (j - i - 1);
                    total = total % 99997867;
                }
            }
        }
        System.out.println(total);
    }

    public static void resolve1(int[] buildings, int gap) {
        int length = buildings.length;
        int start, middle, end;
        long total = 0;
        for (int i = 0; i < length - 2; i++) {
            start = buildings[i];
            int query = query(buildings, start + gap, length);
            long n = query - i - 1;
            if (n > 0) {
                total = total + n * (n + 1) / 2;
                if (total >= 99997867) {
                    total = total % 99997867;
                }
            }
        }
        System.out.println(total);
    }


    //二分法查找
    public static int query(int[] buildings, int target, int length) {
        int start = 0, end = length - 1, middle = 0;
        while (end - start > 0) {
            middle = start + (end - start + 1) / 2;
            if (buildings[middle] < target) {
                start = middle;
            } else if (buildings[middle] == target) {
                start = middle;
                break;
            } else {
                end = middle - 1;
            }
        }
        return start;
    }
}
